package com.shell.customer.base.rx;

import com.shell.customer.base.CusEvent;
import com.shell.customer.base.cmd.CfcaAuthEntAcctForCusCmd;
import com.shell.customer.base.cmd.EsignOpenAcctForCusCmd;
import com.shell.customer.util.CustomerUtil;
import com.shell.framework.command.ChainBase;
import com.shell.framework.command.CommandContext;
import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class AuthEntAcctForCusSubcriber extends OnErrorNotImplementedSubscriber<CusEvent> {
	@Autowired
	private EsignOpenAcctForCusCmd esignOpenAcctForCusCmd;
	@Autowired
	private CfcaAuthEntAcctForCusCmd cfcaAuthEntAcctForCusCmd;

	public void onApplicationEvent(CusEvent event) {
		CommandContext<CusEvent> context = new CommandContext();
		context.setSource(event);
		ChainBase<CusEvent> crb = new ChainBase();
		if (CustomerUtil.onEsign()) {
			crb.add(this.esignOpenAcctForCusCmd);
		} else if (CustomerUtil.onCfca()) {
			crb.add(this.cfcaAuthEntAcctForCusCmd);
		}
		crb.execute(context);
	}
}
